#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n;
    cin >> n;
    string s; cin >> s;

    vector<pair<int, int>> g(n + 1);
    for(int i = 1; i <=  n; i++) {
        int a, b;
        cin >> a >> b;
        g[i] = {a, b};
    }
    vector<int> dp(n + 1, INT_MAX / 2);
    auto dfs = [&](auto&& dfs, int u) {
        if(u == 0) return;
        dp[u] = 0;
        auto [l, r] = g[u];
        if(l == 0 && r == 0) return;
        dfs(dfs, l);
        dfs(dfs, r);
        dp[u] = min(dp[l] + (s[u - 1] != 'L'), dp[r] + (s[u - 1] != 'R'));
    };
    dfs(dfs, 1);
    cout << dp[1] << endl;
}

int main() {
    int t;
    cin >> t;
    while(t--) solve();
    return 0;
}